package com.zhj.algorithm.sort;

import java.util.Arrays;

/**
 * @PackageName:com.zhj.algorithm.sort
 * @ClassName:QuickSort
 * @auter: 朱慧杰
 * @date:2020/8/9 0009 15:54
 **/
public class QuickSort {

    public static void main(String[] args) {
        int[] arr = new int[]{4,6,2,1,3,5,8,7,0};
        quickSort(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    public static void quickSort(int[] arr,int start,int end) {

        if (start < end) {
            // 基准数据
            int stard = arr[start];
            // 记录需要排序的下标
            int low = start;
            int high = end;

            while (low < high) {
                while (low < high && stard <= arr[high]) {
                    high--;
                }
                arr[low] = arr[high];
                while (low < high && stard >= arr[low]) {
                    low++;
                }
                arr[high] = arr[low];
            }
            arr[low] = stard;
            quickSort(arr, 0, low);
            quickSort(arr, high+1, end);
        }

    }

}
